{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "raw_data_x = [\n",
    "    [3.39,2.33],\n",
    "    [3.11,1.78],\n",
    "    [1.34,3.36],\n",
    "    [3.58,4.68],\n",
    "    [2.28,2.87],\n",
    "    [7.42,4.69],\n",
    "    [5.74,3.53],\n",
    "    [9.17,2.51],\n",
    "    [7.79,3.42],\n",
    "    [7.93,0.79]\n",
    "]\n",
    "raw_data_y = [0,0,0,0,0,1,1,1,1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train = np.array(raw_data_x)\n",
    "y_train = np.array(raw_data_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3.39, 2.33],\n",
       "       [3.11, 1.78],\n",
       "       [1.34, 3.36],\n",
       "       [3.58, 4.68],\n",
       "       [2.28, 2.87],\n",
       "       [7.42, 4.69],\n",
       "       [5.74, 3.53],\n",
       "       [9.17, 2.51],\n",
       "       [7.79, 3.42],\n",
       "       [7.93, 0.79]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAB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8DavUUleAzxWVceazrKBG6rqJcArgbcOlvt2g/3AS4APVtWLgf8H/H6zkc41WAa6GfjvTWcBSPKPgdcC/xz4Z8Bzkryh2VR9VXUCeB/wWfrLLQ8CT12s57fQNzBYn/4U0KuqTzedZ5jBW/MvADc2HAXgBuDmwVr1J4BXJPlYs5F+oqq+Pbh+DPhT+mucu8Ep4NSad1l30S/43eSVwP1V9bdNBxn4VeD/VNVKVZ0BPg38y4YzPa2q7qiql1TVy+gvKV+U9XOw0IcafPB4B3Ciqt7fdJ61kkwluXxw+9n0/3F/s9lUUFXvrKqDVdWh//b8c1W1K/aakjxn8OE2g+WMf03/rXHjqur/At9K8nODoUNA4x++r/N6dslyy8BJ4Pokk4PX6iH6n3PtCkn+yeB6Gvi3XMS/u/0X64mGSfJx4OXAFUlOAe+pqjuazDRwA/BG4PhgrRrgXVV1b4OZzroSuHNw1ME+4E+qalcdIrgL/VPgT/uvffYD/62q/qLZSOf4D0BvsLTxv4E3N5znaYN14H8F/Lums5xVVfcluQu4n/5yxtfYXT8B8KkkzwfOAG+tqu9erCf2q/+S1BIuuUhSS1joktQSFroktYSFLkktYaFLUktY6JLUEha6JLXE/wdg3jWNJwy76wAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x_train[y_train==0,0],x_train[y_train==0,1],color='g')\n",
    "plt.scatter(x_train[y_train==1,0],x_train[y_train==1,1],color='r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.array([8.09,3.365])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALE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c8WlUnms6yjuuq6qXAq4G3D5b79oKDwEuBD1fVS4D/B/x+s5FWGywD3Qj896azACT5x8DrgX8O/DPgOUne1Gyqvqo6BXwA+Dz95ZYHgCcv1vNb6OsYrE9/BuhV1WebzjPM4K35F4HrG44CcB1w42Ct+lPAq5J8otlIP1FV3xlcPwr8Kf01zr3gDHBmxbusO+gX/F7yauC+qvrbpoMM/Crwf6pqqarOAZ8F/mXDmZ5WVbdV1Uur6hX0l5Qvyvo5WOhDDT54vA04VVUfbDrPSkkmkjx/cPvZ9P9xf6vZVFBV766qw1XVof/2/AtVtSf2mpI8Z/DhNoPljH9N/61x46rq/wLfTvJzg6EjQOMfvq/xRvbIcsvAaeBlScYHr9Uj9D/n2hOS/JPB9STwb7mIf3cHL9YTDZPkk8ArgcuTnAHeV1W3NZlp4DrgzcDJwVo1wHuq6u4GM513BXD74KiDA8CfVNWeOkRwD/qnwJ/2X/scBP5bVf1Fs5FW+Q9Ab7C08b+Btzac52mDdeB/Bfy7prOcV1X3JrkDuI/+csbX2Vs/AfCZJC8AzgFvr6rvXawn9qv/ktQSLrlIUktY6JLUEha6JLWEhS5JLWGhS1JLWOiS1BIWuiS1xP8HjOVRvksruZ0AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x_train[y_train==0,0],x_train[y_train==0,1],color='g')\n",
    "plt.scatter(x_train[y_train==1,0],x_train[y_train==1,1],color='r')\n",
    "plt.scatter(x[0],x[1],color='b')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## KNN 思路"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 1, 1, 1, 1, 0]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distances = [sqrt(np.sum((item - x) ** 2)) for item in x_train] #求距离 同上上步\n",
    "nearest = np.argsort(distances) #排序,出来坐标\n",
    "k=6\n",
    "topk_y = [y_train[i] for i in nearest[:k]]\n",
    "topk_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import Counter\n",
    "votes = Counter(topk_y) #统计每个出现的次数,相当于投票的过程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predict_y = votes.most_common(1)[0][0]# 票数最多的n个元素 0 是谁,数值是多少\n",
    "predict_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
